<?php defined('RUN_KATANA') or die('Restricted access');
class UserGroup extends Object
{
	public $Title;
	public $Level;
	public $Active;
	public $Users;
	
	public function UserGroup() 
	{ 
		self::setDataChanged(false);
		self::setItemLoaded('Users', false);
	}
	
	public function getLevel() { return intval($this->Level);  }
	/* Users */
	public function getUser($id=0) 
	{
		if($id > 0)
		{
			if(!self::getItemLoaded('Users'))
			{ 
				global $ac;
				$this->Users = $ac->getUsers(0, self::getId()); 
			}
			if(isset($this->Users[$id]))
			{ return $this->Users[$id]; }
		}
	}
	public function getUsers() 
	{
		if(!self::getItemLoaded('Users'))
		{ 
			global $ac;
			$this->Users = $ac->getUsers(0, self::getId()); 
		}
		return $this->Users; 
	}
	/* Groups */
	public function setLevel($val) { $this->Level=intval($val);  }
	public function setUsers($val) { $this->Users=$val; }
	
	public function update()
	{
		if((self::getId() > 0) && (self::getDataChanged()))
		{
			$sql  = 'UPDATE '.DB_PERFIX.'user_groups SET ';
			$sql .= '`title`="'.self::formatText(self::getTitle()).'", ';
			$sql .= '`level`='.self::getLevel().' ';
			$sql .= ' WHERE id='.self::getId().' LIMIT 1;';
			mysql_query($sql);
		}
	}
}
?>